package com.atlin.license;

import com.atlin.service.LicenseService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

/**
 * 在项目启动时安装证书
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class LicenseCheckListener implements ApplicationListener<ContextRefreshedEvent> {
    
    private final LicenseService licenseService;

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        //root application context 没有parent
        ApplicationContext context = event.getApplicationContext().getParent();
        if (context == null) {
            licenseService.licenseInstall();
        }
    }
}
